﻿Imports System.IO
Public Class Log

    Private _Informe As New ArrayList
    ''' <summary>
    ''' Indicamos que el informe es de solo lectura
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Informe As ArrayList
        Get
            Return ArrayList.ReadOnly(_Informe)
        End Get
    End Property
    ''' <summary>
    ''' Añadimos un informe pasando como parametro un informe
    ''' </summary>
    ''' <param name="info"></param>
    ''' <remarks></remarks>
    Public Sub AñadirInforme(ByVal info As String)
        _Informe.Add(info)
        frmPrincipal.txbLog.Text = Today.ToString & " -- " & info & vbNewLine
    End Sub
    ''' <summary>
    ''' Borra un informe de la lista
    ''' </summary>
    ''' <param name="inf"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Borrar(ByVal inf As String) As String
        'El Contains y el Remove funciona porque sobrecarga el Equals
        If Not _Informe.Contains(inf) Then
            Return "Informe no existe"
        End If
        _Informe.Remove(inf)
        Return "Informe eliminado"
    End Function
    ''' <summary>
    ''' Crea el fichero log
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub CrearFicheroLog()
        Dim fich As New IO.StreamWriter("log.txt") 'Crea  el fichero nuevo
        For Each s As String In _Informe
            fich.WriteLine(s)
        Next
        fich.Close()
    End Sub
    ''' <summary>
    ''' Muetra todos los informes
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub VerInforme()
        Dim miUser As New User
        Dim resulInforme As String = ""
        For i As Integer = 0 To _Informe.Count - 1
            resulInforme += Today & miUser.ToString & _Informe(i) & "- "
        Next
    End Sub
End Class
